from pygame_test.MoveRect import MoveRect
from pygame_test.Sector import Sector
import pygame


# 吃豆
def main():
    winx = 300
    winy = 300
    pygame.init()
    screen = pygame.display.set_mode((winx, winy))
    x = 80
    y = 80
    rect_x = x
    rect_y = winy
    r = 50
    b =mouse1= 315 # 上嘴唇张开角度
    e =mouse2= 225 # 下嘴唇张开角度
    mouse0 = 270 # 嘴闭合的角度
    open_speed = 3
    speedx = 1
    speedy = 1
    mouse_open = False

    rects = []
    j = 0 # 计数器, 控制豆子出现的时间
    fclock = pygame.time.Clock()
    while True:
        # x+=speedx
        # y+=speedy

        # spin
        # b += 1
        # e +=1
        # mouse0+=1
        # mouse1+=1

        sector = Sector(x, y, r, (255, 255, 255), b, e)
        if b >= mouse1:
            mouse_open = False
        elif b <= mouse0:
            mouse_open = True
        if mouse_open:
            b += open_speed
            e -= open_speed
        else:
            b -= open_speed
            e += open_speed

        screen.fill((0, 0, 0))
        sector.draw(screen)
        # print(sector.x,sector.y)
        t = int(pygame.time.get_ticks() / 1000)
        j += 1
        if j % 30 == 0 :
            j = 1
            rects.append(MoveRect(rect_x,rect_y,3,3,(6, 168, 255),0,False))
        # print(len(rects))
        for i in rects:
            i.draw(screen)
            i.move(0,-1)
            if i.is_collide(sector.get_rect()):
                rects.remove(i)


        pygame.display.update()
        fclock.tick(40)


if __name__ == '__main__':
    main()
